.pragma library

var types = {
    'image': ['.png', '.jpg', '.gif'],
    'audio': ['.mp3', '.wav'],
    'video': ['.avi', '.mkv']
}

function getFileType(fileName) {
    var lowName = fileName.toLowerCase();
    for(var t in types) {
        if(fileNameEndsWithArray(lowName, types[t])) {
            return t;
        }
    }
    return '';
}

function stringEndsWith1(line, end) {
    var lineLen = line.length;
    console.log('lineLen...>>>', lineLen);
    var endLen = end.length;
    console.log('endLen...>>>', endLen);
    var lastIndex = line.lastIndexOf(end);
    console.log('lastIndex...>>>', lastIndex);
    return (lastIndex >= 0 &&  lastIndex == lineLen - endLen);
}

function fileNameEndsWithArray(name, exts) {
    for (var iext in exts) {
        if (stringEndsWith1(name, exts[iext])) {
            console.log('name...>>>', name);
            console.log('exts[iext]...>>>', exts[iext]);
            return true;
        }
    }
    return false
}

function stringEndsWith2(name, exts) {
    for (var iext in exts) {
        var tarExts = exts[iext]
        var tarExtUpp = tarExts.toUpperCase()
        console.log('tarExts...>>>', tarExts)
        var newExt = name.substr(name.length - tarExts.length);
        var extUpp = newExt.toUpperCase()
        console.log('extUpp...>>>', extUpp)
        console.log('newExt...>>>', newExt)
        console.log('name...>>>', name)
        if (extUpp == tarExtUpp) {
            console.log('extUpp...>>>>>>>>>>>>', extUpp)
            console.log('tarExtUpp...>>>>>>>>>>>', tarExtUpp)
            return true
        }
    }
    return false
}



